
import {  changeMember, getMember, oneMember } from "../../request/api";
import { successAlert } from '../../utils/alert'
const state = {
    tableData: [],//列表
    form: {
        uid: "", //上级分类编号
        nickname: "", //商品分类名称
        phone: "",
        password:"",
        status: 1 //状态1正常2禁用
    },
}

// 2,声明mutations
const mutations = {
    // 专门来修改goods数据
    changemember(state, obj) {
        state.tableData = obj;
    },
    editmember(state, form) {
        state.form = form
    },
    
}

// 3.声明actions
const actions = {
    memberActions(context){
        getMember().then(res=>{
            if(res.code==200){
                context.commit('changemember',res.list)
            }
        })
    },
    oneActions(context,uid){
        oneMember({uid}).then(res=>{
            if(res.code==200){
                // console.log(res.list);
                context.commit('editmember',res.list)
            }
        })
    },
    updateActions(context,obj){
        changeMember(obj).then(res=>{
            if(res.code==200){
                successAlert(res.msg)
                // console.log(res.list);
                context.dispatch('memberActions')

            }
        })
    }
    

}
// 4.声明getters
const getters = {
    tableData(state) {
        return state.tableData
    },
    form(state) {
        return state.form
    },
}

export default {
    state,
    mutations,
    actions, getters,
    namespaced: true,//使用命名
}